package com.dong.nettyconcurrent.c05_websocket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class MyWebSocketServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline()
                .addLast(new HttpServerCodec())
                .addLast(new ChunkedWriteHandler())//写块...
                .addLast(new HttpObjectAggregator(8192))//http 消息/内容聚合 到 fullHttpRequest./response , http粘包
                .addLast(new WebSocketServerProtocolHandler("/ws"))  //web socket 握手,ping pang .close     frame
                .addLast(new MyTextWebSocketFrameHandler())
                ;
    }
}
